home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / ezirc12j.zip / setup.cmd < prev   
OS/2 REXX Batch file  |  1997-06-15  |  10KB  |  347 lines

  1. /*    Setup script for EZirc
  2.  
  3.   Creates folder and various other objects
  4.   Adjust paths in INI and scripts for INSTALL path.
  5. */
  6.  
  7. Call Init
  8.  
  9. Setup:
  10. call getkeypress
  11. if proceed = "QUIT" then signal end
  12. if proceed = "NO" then signal setup
  13.  
  14. Lets_Go:
  15. say '     * Please wait while EZirc is installed to 'dir
  16. say ' '
  17.  
  18. /* Check that destination exists, if not make it. */
  19. call Directory_Make
  20.  
  21. /* Define Files to setup on the desktop */
  22. docs = dir"\html\EZIRC.HTM"
  23. exename = dir'\EZIRC.EXE'
  24.  
  25. say '     Unpacking Distribution Package to 'dir
  26. '@unzip install -d 'dir' > nul'
  27.  
  28. say '     Customizing the INI'
  29. call ModifyINI
  30. say '     Customizing paths in scripts.'
  31. call ModifyScripts
  32. say '     Creating WPS objects'
  33. call CreateObjects
  34. call SysOpenObject "<EZIRC_FLDR>","DEFAULT","TRUE"
  35.  
  36. End:
  37. say '     ALL DONE!'
  38. return
  39.  
  40. /* ===================================================== */
  41. /*               procedures below here.                  */
  42. /* ===================================================== */
  43.  
  44. Init :
  45.  
  46.   call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  47.   call SysLoadFuncs
  48.  
  49. /* Define Variables */
  50. dir = directory()
  51. env='OS2ENVIRONMENT'
  52. UserIdent=value('user',,env)
  53. if UserIdent = '' then UserIdent = 'yourID'
  54. testid=pos('@',UserIdent)
  55. if testid > 0 then UserIdent = 'yourID'
  56. realname = 'Your Realname String'
  57. nickname = 'YourNick'
  58.  
  59. /* trace ?r */
  60. return
  61.  
  62. greeting:
  63.  
  64. call SysCls
  65. Say ' '
  66. Say ' '
  67. say '     EZirc Installation.'
  68. say ' '
  69. Say '     This Script will install EZIRC and customise files for you.'
  70. Say ' '
  71. Say '     Current Settings for installation :'
  72. Say ' '
  73. Say '        1)  Install Path : 'dir
  74. Say '        2)  Your User ID : 'UserIdent
  75. Say '        3) Your Realname : 'realname
  76. Say '        4) Your NickName : 'nickname
  77. Say ' '
  78. Say '     Press Enter to Install with above Settings, or # to change. Q to Quit.'
  79. proceed = "NO"
  80. return
  81.  
  82. getkeypress:
  83. call greeting
  84. say ' '
  85. key = SysGetKey(NOECHO)
  86. say ' '
  87. keyhex = C2X(key)
  88. if keyhex='0D'
  89.    then  /* if key is RETURN */
  90.      proceed = "YES"
  91.    else
  92.     do
  93.       key = translate(key)
  94.       if key = 1
  95.          then
  96.            do
  97.              Say '    Enter Full path to install to, without the trailing /'
  98.              Say '    ie  d:\ezirc     or  d:\internet\ezirc'
  99.              Say ' '
  100.              result=charout(,'    Path : ')
  101.              string = '                                                                                '
  102.              Parse Upper Pull string .
  103.              dir = string
  104.              Call Directory_Check
  105.            end
  106.          else
  107.            if key = 2
  108.               then
  109.                 do
  110.                 Say '    Enter your User ID from your ID in your email address'
  111.                 Say '    ie if your email is xyz@provider.com  you enter xyz'
  112.                 Say ' '
  113.                 result=charout(,'    UserID : ')
  114.                 string = '                                                                                '
  115.                 Parse Pull string .
  116.                 UserIdent = String
  117.                 end
  118.               else
  119.                 if key = 3
  120.                    then
  121.                      do
  122.                      Say '    Enter the string you want in your Realname Field when you are connected.'
  123.                      Say '    A typical string might be    Firstname in City/state'
  124.                      Say ' '
  125.                      result=charout(,'    Realname : ')
  126.                      string = '                                                                                '
  127.                      Parse Pull string
  128.                      Realname = string
  129.                      end
  130.                    else
  131.                      if key = 4
  132.                         then
  133.                           do
  134.                           Say '    Enter the NICKNAME you would like to use while on IRC.'
  135.                           Say '    Rules for Nicknames are Max 9 Char. And no special Characters'
  136.                           Say '    Characters like _ for a space are allowed.'
  137.                           Say '    Avoid the | char, as it is used in scripts to seperate multiple commands.'
  138.                           Say ' '
  139.                           result=charout(,'    NickName : ')
  140.                           string = '                                                                                '
  141.                           Parse Pull string .
  142.                           NickName = String
  143.                           end
  144.                         else
  145.                           if key = 'Q'
  146.                              then
  147.                                proceed = "QUIT"
  148.     end
  149. return
  150.  
  151. Directory_Check:
  152.        /* Check the DRIVE exists */
  153.        testdrive=substr(dir,1,2)
  154.        info = SysDriveInfo(testdrive)
  155.        if info = ''
  156.          then /* No Drive, then lets go back for a new KEY Press */
  157.            do
  158.              say '     Destination Drive Doesn'"'"'t Exist.'
  159.              say '     Resetting to current path'
  160.              dir = directory()
  161.              say '     Press any key to continue'
  162.              key = SysGetKey()
  163.            end
  164.          else
  165.            do
  166.              /* in case user entered a trailing /  Strip it. */
  167.              dir = strip(dir,'T','/')
  168.              dir = strip(dir,'T','\')
  169.            end
  170. return
  171.  
  172. Directory_Make:
  173.  
  174. /* Drive Exists, so lets make the path */
  175. say '     Creating Path 'dir
  176. rc = SysMkDir(dir)
  177. if rc = 0
  178.    then
  179.     say'     Directory creation was successful.'
  180.    else
  181.     if rc = 5
  182.        then
  183.         say '     Directory Already Exists. So lets use it.'
  184.        else
  185.         DO
  186.          /* Any other Return Code is an Error, so report and FAIL */
  187.          if rc = 2   then say'     * Error.  File not found.'
  188.          if rc = 3   then say'     * Error.  Path not found.'
  189.          if rc = 26  then say'     * Error.  Not a DOS disk.'
  190.          if rc = 87  then say'     * Error.  Invalid parameter.'
  191.          if rc = 108 then say'     * Error.  Drive locked.'
  192.          if rc = 206 then say'     * Error.  Filename exceeds range.'
  193.          say '     * Fatal Error, can not continue.'
  194.          Signal End
  195.         END
  196. return
  197.  
  198. ModifyINI:
  199. /* Source File to patch */
  200. source= dir"\ezirc.ini"
  201.  
  202. /* Lets Load it */
  203. call loadfile
  204.  
  205. /* for all the following Set the Old and New strings then Search & Replace */
  206. ReplaceString = 'x:'
  207. newstring = dir
  208. call SearchnReplace
  209.  
  210. replacestring = 'yourID'
  211. newstring = UserIdent
  212. call SearchnReplace
  213.  
  214. replacestring = 'Your_Realname_String'
  215. newstring = realname
  216. call SearchnReplace
  217.  
  218. replacestring = 'YourNick'
  219. newstring = nickname
  220. call SearchnReplace
  221.  
  222. /* Done with this file, lets save it. */
  223. Call SaveFile
  224.  
  225. Return
  226.  
  227. ModifyScripts:
  228. /* adjust driver letters in scripts/aliases from x: to install_drive */
  229. ReplaceString = 'x:'
  230. newstring = dir
  231.  
  232. source= dir"\alias\type_it.cmd"
  233. call ProcessFile
  234.  
  235. source= dir"\script\finger.cmd"
  236. call ProcessFile
  237.  
  238. source= dir"\script\page.cmd"
  239. call ProcessFile
  240.  
  241. source= dir"\script\sendfile.cmd"
  242. call ProcessFile
  243.  
  244. source= dir"\script\sidoh.cmd"
  245. call ProcessFile
  246.  
  247. source= dir"\script\siwoohoo.cmd"
  248. call ProcessFile
  249.  
  250. Return
  251.  
  252. ProcessFile:
  253. call loadfile
  254. call SearchnReplace
  255. Call savefile
  256. return
  257.  
  258. CreateObjects:
  259.  
  260.     If  SysCreateObject("WPFolder","EZirc for Os/2 ","<WP_DESKTOP>","OBJECTID=<EZIRC_FLDR>") then
  261.     do
  262.           If SysCreateObject("WPProgram", "EZirc", "<EZIRC_FLDR>","EXENAME="exename";STARTUPDIR="dir";PROGTYPE=PM")  Then
  263.           do
  264.                Say '     Folder and program objects have been created'
  265.                url1 = 'file:///'docs
  266.                rc = SysCreateObject( 'WPUrl', 'EZirc Manual', '<EZIRC_FLDR>', 'OBJECTID=<EZIRC_MANUAL>;URL='url1';', 'replace' )
  267.           end
  268.           Else
  269.              Say '     * Could not create program object'
  270.     End
  271.     Else
  272.        Say '     * Could not create folder '
  273.  
  274. return
  275.  
  276. LoadFile:
  277.  
  278. lines.0=0
  279.    /* open file for read */
  280.    resultCode = stream( source , 'C', 'OPEN READ')
  281.    if resultCode  \= 'READY:' then
  282.    do
  283.       say 'stream open of 'source' returned "'resultCode'"'
  284.       exit
  285.    end
  286.    /* load each line and store in array lines */
  287.    do while lines( source )
  288.       newline = linein( source )
  289.       /* Store lines in Array LINES */
  290.       count= lines.0 + 1
  291.       lines.0 = count
  292.       lines.count=newline
  293.    end
  294.    /* close file */
  295.    resultCode = stream( source, 'C', 'CLOSE')
  296.    if resultCode  \= 'READY:' then
  297.    do
  298.       say 'stream close returned "'resultCode'"'
  299.       exit
  300.    end
  301.  
  302. Return
  303.  
  304. SearchnReplace:
  305. /* Search for replacestring and replace with NewString */
  306.  
  307. do i=1 to lines.0
  308.    replace_len=length(replacestring)
  309.    dlexist = pos(replacestring,lines.i)
  310.    if dlexist > 0
  311.     then
  312.       do
  313.       lines.i = delstr(lines.i,dlexist,replace_len)
  314.       lines.i = insert(newstring,lines.i,dlexist-1)
  315.       end
  316.     else
  317.       NOP
  318. end
  319. Return
  320.  
  321. SaveFile:
  322.    '@del 'source
  323.    /* open file for write */
  324.    resultCode = stream( source , 'C', 'OPEN WRITE')
  325.    if resultCode  \= 'READY:' then
  326.    do
  327.       say 'stream open of 'source' returned "'resultCode'"'
  328.       exit
  329.    end
  330.  
  331.    /* load each line and store in array lines */
  332.    do i=1 to lines.0
  333.       writeline = lines.i
  334.       rc = lineout( source , writeline )
  335.    end
  336.  
  337.    /* close file */
  338.    resultCode = stream( source, 'C', 'CLOSE')
  339.    if resultCode  \= 'READY:' then
  340.    do
  341.       say 'stream close returned "'resultCode'"'
  342.       exit
  343.    end
  344.  
  345. return
  346.  
  347.